package com.example.springboot.controller;

import com.example.springboot.common.OBJ;
import com.example.springboot.common.Result;
import com.example.springboot.service.WithdrawalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/withdrawal")
public class WithdrawalController {
    @Autowired
    private WithdrawalService withdrawalService;

    @GetMapping("/list")
    public Result findAll() {
        return Result.success(withdrawalService.findAll());
    }

    @PostMapping("/add")
    public Result insert(@RequestBody Withdrawal withdrawal) {
        withdrawalService.insert(withdrawal);
        return Result.success("增加成功");
    }

    @PutMapping("/update")
    public Result update(@RequestBody Withdrawal withdrawal) {
        withdrawalService.update(withdrawal);
        return Result.success("修改成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        withdrawalService.delete(id);
        return Result.success("删除成功");
    }

    @PostMapping("/deleteList")
    public Result deleteList(@RequestBody List<Integer> ids) {
        withdrawalService.deleteList(ids);
        return Result.success("删除成功");
    }

    @PostMapping("/selectByManyCondition")
    public Result selectByManyCondition(@RequestBody OBJ obj) {
        return Result.success(withdrawalService.selectByManyCondition(obj.getWithdrawal(), obj.getCurrentPage(), obj.getPageSize()));
    }
}

